<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>xeokit Example</title>
    <link href="../css/pageStyle.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<div class="slideout-sidebar">
    <h1>SpriteMarker</h1>
    <h2>A Marker with a billboarded and textured quad attached to it</h2>
    <h3>Components used</h3>
    <ul>
        <li>
            <a href="../../docs/class/src/viewer/Viewer.js~Viewer.html" target="_other">Viewer</a>
        </li>
        <li>
            <a href="../../docs/class/src/viewer/scene/mesh/Mesh.js~Mesh.html"
               target="_other">Mesh</a>
        </li>
        <li>
            <a href="../../docs/class/src/viewer/scene/geometry/ReadableGeometry.js~ReadableGeometry.html"
               target="_other">ReadableGeometry</a>
        </li>
        <li>
            <a href="../../docs/function/index.html#static-function-buildTorusGeometry"
               target="_other">buildTorusGeometry()</a>
        </li>
        <li>
            <a href="../../docs/class/src/viewer/scene/materials/PhongMaterial.js~PhongMaterial.html"
               target="_other">PhongMaterial</a>
        </li>
        <li>
            <a href="../../docs/class/src/viewer/scene/materials/Texture.js~Texture.html"
               target="_other">Texture</a>
        </li>
        <li>
            <a href="../../docs/class/src/viewer/scene/marker/SpriteMarker.js~SpriteMarker.html"
               target="_other">SpriteMarker</a>
        </li>
    </ul>
</div>
</body>

<script id="source" type="module">

    import {
        Viewer,
        SpriteMarker,
        Mesh,
        PhongMaterial,
        ReadableGeometry,
        Texture,
        buildTorusGeometry
    } from "../../dist/xeokit-sdk.min.es.js";

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true
    });

    viewer.scene.camera.eye = [0, 0, 25];
    viewer.scene.camera.look = [0, 0, 0];
    viewer.scene.camera.up = [0, 1, 0];

    new Mesh(viewer.scene, {
        geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({
            center: [0, 0, 0],
            radius: 3.5,
            tube: 1.5,
            radialSegments: 32,
            tubeSegments: 24,
            arc: Math.PI * 2.0
        })),
        material: new PhongMaterial(viewer.scene, {
            ambient: [0.9, 0.3, 0.9],
            shininess: 30,
            diffuseMap: new Texture(viewer.scene, {
                src: "../../assets/textures/diffuse/uvGrid2.jpg"
            })
        }),
        rotation: [0, 90, 0]
    });

    new SpriteMarker(viewer.scene, {
        worldPos: [-10, 0, 0],
        src: "../../assets/textures/diffuse/uvGrid2_512x1024.jpg",
        size: 5,
        occludable: true
    });

    new SpriteMarker(viewer.scene, {
        worldPos: [+10, 0, 0],
        src: "../../assets/textures/diffuse/uvGrid2_1024x512.jpg",
        size: 4,
        occludable: true
    });

    function textToBase64(message, fontsize = 120, fontface = 'Arial') {
        const canvas = document.createElement('canvas');
        const context = canvas.getContext('2d');
        context.font = `Bold ${fontsize}px ${fontface}`;
        context.fillStyle = 'rgba(0, 0, 0, 1.0)';
        canvas.width = context.measureText(message).width;
        canvas.height = (fontsize + 4);
        context.fillText(message, 0, fontsize);
        return canvas.toDataURL();
    }
</script>
</html>